<template>
	<view class="uni-fab-box">
		<view v-if="!projectItemLists || projectItemLists.length === 0" class="uni-flex uni-row" 
			style="-webkit-justify-content: center;justify-content: center;">
			<view class="none-tip-text">暂无数据</view>
		</view>
		<view v-else>
			<uni-card v-for="(item,index) in projectItemLists" :title="item.itemName" isShadow @click="handleProjectItemClick(item)">
				<view><text class="content-box-text">单&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号&nbsp;&nbsp;&nbsp;：{{item.itemNo}}</text></view>
				<view><text class="content-box-text">预算金额：{{item.budgetAmount}}</text></view>
				<view><text class="content-box-text">预算用量：{{item.budgetDosage}}</text></view>
				<view><text class="content-box-text">实际金额：{{item.factAmount}}</text></view>
				<view><text class="content-box-text">实际数量：{{item.factDosage}}</text></view>
				<view><text class="content-box-text">单&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;位&nbsp;&nbsp;&nbsp;：{{item.unit}}</text></view>
				<view><text class="content-box-text">描&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;述&nbsp;&nbsp;&nbsp;：{{item.itemDesc}}</text></view>
			</uni-card>
		</view>
	</view>
</template>

<script>
	import { getProjectItemInfo } from '@/api/projectItemInfo.js'
	export default {
		onLoad(options){
			if(!options || !options.id) {
				uni.navigateBack({delta:1});
				return;
			}
			this.projectListQuery.param.projectId = decodeURIComponent(options.id);
		},
		onReachBottom(){
			if(this.isLoading || this.projectItemLists.length >= this.projectItemTotal) {
				return;
			}
			this.isLoading = true;
			this.projectListQuery.page = this.projectListQuery.page + 1;
			this.getProjectItemLists();
		},
		onPullDownRefresh() {
			this.projectListQuery.page = 1;
			this.projectItemLists = [];
			this.getProjectItemLists();
		},
		onShow() {
			this.projectListQuery.page = 1;
			this.projectItemLists = [];
			this.getProjectItemLists();
		},
		data() {
			return {
				projectListQuery: {
					page: 1,
					size: 10,
					param: {
						projectId: undefined
					}
				},
				projectItemLists: [],
				projectItemTotal: 0,
				isLoading: false
			}
		},
		methods: {
			getProjectItemLists() {
				getProjectItemInfo(this.projectListQuery).then(resp => {
					resp.datas.datas.forEach(x => this.projectItemLists.push(x))
					this.projectItemTotal = resp.datas.total;
					this.isLoading = false;
					uni.stopPullDownRefresh();
				})
				.catch(error => {
					uni.stopPullDownRefresh();
					uni.showToast({
						title: error,
						icon: 'none',
						duration: 1000
					});
				});
			},
			handleProjectItemClick(item) {
				uni.navigateTo({
					url: "/pages/projectItemImageInfo/project_item_image_lists?id="+ item.id
				})
			}
		}
	}
</script>

<style>
</style>
